package com.ai.dmc.index.web.action;

import com.ai.dmc.index.common.InitParam;
import com.ai.dmc.index.common.bean.StaffSessBean;
import com.ai.dmc.index.common.util.CryptionUtil;
import com.ai.dmc.index.web.util.SessionInfoUtil;
import com.ai.frame.bean.InputObject;
import com.ai.frame.bean.OutputObject;
import com.ai.frame.logger.Logger;
import com.ai.frame.logger.LoggerFactory;

import net.sf.json.JSONObject;

/**
 */
public class LogoutAction extends BaseAction {
	private static final long serialVersionUID = -3579032710235743396L;
	private static final Logger logger = LoggerFactory.getActionLog(LogoutAction.class);
	private StaffSessBean session;
	private String userId;
	private String pwd;
	
	public void init() {
		 session = SessionInfoUtil.getStaffSessBean(
				this.getRequest().getSession());
		if (null != session) {
			 userId = session.getUserId();
			 pwd=session.getUserPassword();
			}
	}
	
	public String execute(){
		logger.info("logout", "Start");
		this.init();
		//JSONObject logoutInfo = new JSONObject();
		InputObject inputObj = super.getInputObject();
		inputObj.getParams().put("userId",userId);
		inputObj.getParams().put("userPassword",pwd);
		
//		String userPassword = inputObj.getParams().get("userPassword");
//		if ((null == userId || userId.trim().length() == 0)
//				&& (null == userPassword
//						|| userPassword.trim().length() == 0)) {
//			loginInfo.put("loginCode", "1");
//			loginInfo.put("loginDesc", "账号密码错误，请重新输入");
//			super.sendJson(loginInfo.toString());
//			return null;
//		}
//		
		OutputObject outPutObject = super.getOutputObject();
		//本地session注销
		if(inputObj.getParams().get("jspName").equals("logout.jsp")){
		SessionInfoUtil.removeStaffSessBean(this.getRequest().getSession());
		}
//		StaffSessBean sessionBean = (StaffSessBean) outPutObject.getObject();
////		userPassword = CryptionUtil.encrypt(userPassword);
//		if (null == sessionBean) {
//			loginInfo.put("loginCode", "11");
//			loginInfo.put("loginDesc", "用户不存在");
//		} else if (!userPassword.equals(sessionBean.getUserPassword())) {
//			loginInfo.put("loginCode", "1");
//			loginInfo.put("loginDesc", "账号密码错误，请重新登录");
//		} else if (!"1".equals(sessionBean.getStatus())) {
//			loginInfo.put("loginCode", "2");
//			loginInfo.put("loginDesc", "此账号已停用，请联系管理员");
//		}
//
//		// 验证失败
//		if (loginInfo.has("loginCode")) {
//			outPutObject.setObject(loginInfo);
//			super.sendJson(super.convertOutputObject2Json(outPutObject));
//			return null;
//		}
//		loginInfo.put("loginCode", "0");
//		loginInfo.put("loginDesc", "登录成功");
//		outPutObject.setObject(loginInfo);
//		super.getSession().setAttribute("dtkl_session", sessionBean);
		super.sendJson(super.convertOutputObject2Json(outPutObject));
		logger.info("logout", "End");
		return null;
	}
}
